const mongoose = require("./db")
const moment = require('moment-timezone');
moment.tz.setDefault('Asia/Shanghai'); // 将默认时区设置为上海时区

const foodlistschema = new mongoose.Schema({
    imgs: String,
})

const fidschema = new mongoose.Schema({
    imgs: String,
    name: String,
    kgs: String,
    price: Number,
    sid: {
        type: mongoose.Types.ObjectId,
        ref: 'sxmenu'
    },
    num: Number,
    flags: {
        type: Boolean,
        default: false
    }

})

const fidmodel = mongoose.model('ztyfid', fidschema, 'ztyfid')

const cidschema = new mongoose.Schema({
    name1: String,
    name1img: String,
    sid: {
        type: mongoose.Types.ObjectId,
        ref: 'sxmenu'
    }

})

const cidmodel = mongoose.model('ztycid', cidschema, 'ztycid')
const bbSchema = mongoose.Schema({
    name: String,
})
const sxmenuschema = new mongoose.Schema({
    imags: String,
    title: String,
    times: Date,
    nums: Number,
    flag: {
        default: false,
        type: Boolean
    },
    types: Number,
    foodlist: [foodlistschema],



})

const sxmenumodel = mongoose.model('sxmenu', sxmenuschema, 'sxmenu')


// 左盖豪分类
const zgh_cate_Schema = new mongoose.Schema({
    title: String,
    price: Number,
    img: String,
    cate: String,
    ren: Number,
    num: {
        type: Number,
        default: 1
    }
})

const zgh_cate_Model = mongoose.model('zgh_cate', zgh_cate_Schema, 'zgh_cate')

// 左盖豪积分
const zgh_jf_Schema = new mongoose.Schema({
    num: {
        type: Number,
        default: 1
    },
    day: Number,
    title: String,
    you: Number,
    cate: {
        type: Number,
        default: 0
    },
    date: {
        type: Date,
        default: new Date()
    },
    pid: {
        type: mongoose.Types.ObjectId,
        ref: 'zgh_jf'
    }
})

const zgh_jf_Model = mongoose.model('zgh_jf', zgh_jf_Schema, 'zgh_jf')

const zgh_yhj_Schema = new mongoose.Schema({
    title: Number,
    man: Number,
    price: Number,
    date: {
        type: Date,
        default: moment().tz('Asia/Shanghai')
    },
    cate: {
        type: Boolean,
        default: true
    }

})

const zgh_yhj_Model = new mongoose.model('zgh_yhj', zgh_yhj_Schema, 'zgh_yhj')




// 支付页 --- 于瑞涛
const yrtZhitou = mongoose.Schema({
    title: String
})
const yrtZhibody = mongoose.Schema({
    bian: String,
    title: String,
    flag: Number,
    imgs: Array,
    num: Number,
    price: Number,
    tid: {
        type: mongoose.Types.ObjectId,
        ref: "yrtzhifu"
    }

})
// 登录
const loginSchema = new mongoose.Schema({
    username: String,
    phone: String,
    code: Number,     //验证码
    codeCreateAt: Date
}) //验证码创建时间
const UserSchema = new mongoose.Schema({
    username: String,
    phone: {
        type: String,
        required: true,
        unique: true,
    },
    code: {
        type: String,
        required: false,
    },
    img: String
})
const bbModel = mongoose.model('bb', bbSchema, 'bb')

const Yrtzhifu = mongoose.model('yrtzhifu', yrtZhitou, "yrtzhifu")
const Yrtzhibdy = mongoose.model('yrtzhibdy', yrtZhibody, 'yrtzhibdy')
let loginModel = mongoose.model('login', loginSchema, 'login')
let UserModel = mongoose.model('user', UserSchema, 'user')
// UserModel.create([

// loginModel.create([
//     {
//         username: '张三',
//         phone: '18830216850',
//         code: 123456,
//         img: 'https://www.axured.cn/assets/axurefiles/dd9eb05e6076c704b2c1e0053def3cc6/images/%E4%BA%A7%E5%93%81%E8%AF%A6%E6%83%85/u1927.png'
//     }

// ])

// Yrtzhifu.create({
//     title:"已完成"
// })

// Yrtzhibdy.create({
//     bian: "FF20200317",
//     title: "待支付",
//     flag: 0,
//     imgs: [
//         "https://www.axured.cn/assets/axurefiles/dd9eb05e6076c704b2c1e0053def3cc6/images/%E9%A6%96%E9%A1%B5/u215.png",
//         "https://www.axured.cn/assets/axurefiles/dd9eb05e6076c704b2c1e0053def3cc6/images/%E9%A6%96%E9%A1%B5/u215.png",
//         "https://www.axured.cn/assets/axurefiles/dd9eb05e6076c704b2c1e0053def3cc6/images/%E9%A6%96%E9%A1%B5/u255.png",
//         "https://www.axured.cn/assets/axurefiles/dd9eb05e6076c704b2c1e0053def3cc6/images/%E9%A6%96%E9%A1%B5/u255.png"
//     ],
//     num: 1,
//     price: 10,
//     tid: "6529266f93e836ec317e419a"
// })

// ayq -- 地址
const addrSchema = mongoose.Schema({
    name: String,
    tel: String,
    region: Array,
    detailaddr: String,
    ems: String,
    default: {
        type: Boolean,
        default: false
    }
})
const addrModel = mongoose.model('ayqaddr', addrSchema, 'ayqaddr')

// addrModel.create({
//     name:'李四',
//     tel:'13000000000',
//     region:['安徽', '芜湖', '弋江区'],
//     detailaddr:'安徽芜湖弋江区55号',
//     ems:'123456',
//     default:true
// })

// ayq -- 推送设置
const ayqpushSchema = mongoose.Schema({
    title:String,
    push:Boolean
})
const ayqpushModel = mongoose.model('ayqpush',ayqpushSchema,'ayqpush')

// ayqpushModel.create({
//     title:'物流提醒',
//     push:true
// })

// ayq -- 意见反馈
const feedbackSchema = mongoose.Schema({
    type:String,
    content:String,
    contmanner:String,
    imgs:Array
})
const feedbackModel = mongoose.model('feedback',feedbackSchema,'feedback')

module.exports = {
    bbModel,
    Yrtzhifu,
    Yrtzhibdy,
    zgh_cate_Model,
    sxmenumodel,
    ayqpushModel,
    feedbackModel,
    UserModel,
    fidmodel,
    cidmodel,
    zgh_jf_Model,
    addrModel,
    zgh_yhj_Model
}
